<?php
/* @var $this UserServiceController */
/* @var $model UserService */

$this->breadcrumbs=array(
	Yii::t('base','User Services')=>array('admin'),
	Yii::t('base','Distribution'),
);
?>

<h1><?php echo Yii::t('base','Distribution equipment')?></h1>

<?php
/* @var $this UserServiceController */
/* @var $model UserService */
/* @var $form CActiveForm */
$user_id = Yii::app()->request->getParam(user_id);
if($user_id!=""){
	$user=User::model()->find('user_id='.$user_id);
}
$level=yii::app()->user->level;
$id=yii::app()->user->id;
$custom_id=yii::app()->request->getParam(custom_id);
if($custom_id!=""){
$custom=Custom::model()->find('custom_id='.$custom_id);
}
?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
		'id'=>'user-service-form',
		'enableAjaxValidation'=>false,
)); ?>

	<p class="note"><?php echo Yii::t('base','Fields with <span class="required">*</span> are required.')?></p>

	<?php echo $form->errorSummary($model); ?>
		<input type="hidden" id="level2" name="level2" value="<?php echo $user->level;?>"/>
		<?php
			$equipment_sql1="SELECT * FROM zy_equipment WHERE service_id=12 and is_used=0 order by equipment_id asc
		";
			$connection = Yii::app()->db;
			$command = $connection->createCommand($equipment_sql1);
			$results = $command->queryAll();
		?>
			<div class="row">
					<?php 
					if(count($results)<=1){
						echo "No equipment can receive","</br>";
					}
					?>
					<input name="user_id" id="user_id" type="hidden" value="" />
					<input name="creater" id="creater" type="hidden" value="<?php echo $id;?>" />
					<input name="access_id" id="access_id" type="hidden" value="<?php echo $user_id;?>" />
			</div>
				<?php if(count($results)>1){?>
				<div class="row">
					可用设备:<br/>
					<?php for($i=0;$i<count($results);$i++){ 
						$userservice=UserService::model()->find('equipment_id='.$results[$i]['equipment_id'].' AND isreback=2');
					?>
					<input type="checkbox" name="equipment[]" value="<?php echo $results[$i]['equipment_id'];?>" /><?php echo $results[$i]['equipment_number'];?>
					<?php  if($userservice->package_id!=0){
						$package=Package::model()->find('package_id='.$userservice->package_id);
						echo '('.$package->package_name.')';
					}?>
					&nbsp;&nbsp;&nbsp;<?php if(($i+1)%6==0&&$i>=2) echo "<br />"; } ?>
				</div>
	<div class="row buttons">
	<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('base','Create') : Yii::t('base','Save')); ?>
	<?php } ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->